package com.kzj.mls.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.alibaba.fastjson.JSON;
import com.kzj.mls.R;
import com.kzj.mls.beans.ServiceBookBean;
import com.kzj.mls.global.App;
import com.kzj.mls.global.Constant;
import com.kzj.mls.recyclerCard.basic.MaterialListView;
import com.kzj.mls.recyclerCard.card.service.ServiceFlow1Card;
import com.kzj.mls.recyclerCard.card.service.ServiceMaterilistViewFlow;
import com.kzj.mls.recyclerCard.card.service.ServiceMaterilistViewProduct;
import com.kzj.mls.recyclerCard.card.service.ServiceViewPagerCard;
import com.kzj.mls.request.BaseResponse;
import com.kzj.mls.request.ICallBackForRequestServer;
import com.kzj.mls.request.RequestServerManager;

/**
 * Created by xyg on 2015/11/4.
 */
public class ServiceActivity extends GBaseActivity {

    MaterialListView materialListView;
    RelativeLayout relativeLayoutBottom;
    String SID;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentViewFor720_1280(R.layout.activity_service);
        findViewByIds();
        initDatas();
        fillArrayInListView();
    }

    @Override
    protected void findViewByIds() {
        materialListView = (MaterialListView) findViewById(R.id.material_listview);
        relativeLayoutBottom = (RelativeLayout) findViewById(R.id.relativeLayoutBottom);
        relativeLayoutBottom.setOnClickListener(this);
    }

    @Override
    protected void initDatas() {
        SID = getIntent().getStringExtra(ServiceOrderActivity.TagSID);
        setTopTitle("服务介绍");
        setLeftImg(View.VISIBLE, R.drawable.back);
    }

    @Override
    protected void fillArrayInListView() {
        ServiceViewPagerCard serviceViewPagerCard = new ServiceViewPagerCard(this);
        materialListView.add(serviceViewPagerCard);

        //服务流程文字
        ServiceFlow1Card serviceFlow1Card = new ServiceFlow1Card(this);
        materialListView.add(serviceFlow1Card);

        ServiceMaterilistViewFlow serviceMaterilistViewFlow = new ServiceMaterilistViewFlow(this);
        materialListView.add(serviceMaterilistViewFlow);

        //产品介绍文字
        ServiceFlow1Card serviceFlow1Card2 = new ServiceFlow1Card(this);
        materialListView.add(serviceFlow1Card2);

        ServiceMaterilistViewProduct serviceMaterilistViewProduct = new ServiceMaterilistViewProduct(this);
        materialListView.add(serviceMaterilistViewProduct);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.relativeLayoutBottom:
                if (App.getInstance().getUserBean() != null) {
                    Intent intent = new Intent(this, ServiceOrderActivity.class);
                    intent.putExtra(ServiceOrderActivity.TagSID, "121");
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(this, LoginActivity.class);
                    intent.putExtra("activity","service");
                    startActivity(intent);
                }
                break;
            default:
                break;
        }
    }

    private void TaskGetServiceBook(String lng, String lat, String goods_id, String city) {
        RequestServerManager.getInstance().handleMethod((GBaseActivity) getActivity(), null, null, false,
                Constant.getRootUrl() + Constant.Action.Action_booking, RequestServerManager.getInstance().
                        getRequestParams(Constant.Action.Action_booking, lng, lat, goods_id, city), BaseResponse.class, new ICallBackForRequestServer<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse result) {
                        ServiceBookBean serviceBookBean = JSON.parseObject(JSON.toJSONString(result.getRetval()), ServiceBookBean.class);

                        materialListView.getAdapter().notifyDataSetChanged();
                    }

                    @Override
                    public void onFail(int type, String errorMsg, String json) {
                        App.getInstance().showToast(errorMsg + "");
                    }
                });
    }
}
